#include "Rp2Skeleton.h"

using namespace Rp2;

//---------------------------------------------------------------------------------------------------
Skeleton::Skeleton()
{
}
//---------------------------------------------------------------------------------------------------
Skeleton::~Skeleton()
{
}
//---------------------------------------------------------------------------------------------------
Bone* Skeleton::CreateBone(std::string& rkBoneName, int iBoneID, int iParentID)
{
	for (int i = 0; i < (int)m_kBones.size(); i++)
	{
		if (rkBoneName == m_kBones[i]->GetName())
		{
			return m_kBones[i];
		}
	}

	Bone* pkBone = new Bone(rkBoneName, iBoneID, iParentID);
	m_kBones.push_back(pkBone);
	return pkBone;
}
//---------------------------------------------------------------------------------------------------
void Skeleton::ConstructHierarchy()
{
	for (int i = 0; i < (int)m_kBones.size(); i++)
	{
		Bone* pkBone = m_kBones[i];
		if (pkBone->GetParentID() >= 0)
		{
			// get the parent joint
			Bone* pkParent = GetBone(pkBone->GetParentID());
			assert(pkParent);
			pkParent->AttachChild(pkBone);
		}
		else
		{
			pkBone->HasParent = false;
			m_kRootIndices.push_back(pkBone->GetBoneID());
		}
	}
}
//---------------------------------------------------------------------------------------------------